package com.smh.a12Test6;

import java.io.*;
import java.net.Socket;

public class Client {
    public static void main(String[] args) throws IOException {

        //解决文件名重名问题
        //客户端:将本地文件上传到服务器。按收服务器的反馈。
        //服务器:接收客户端上传的文件，上传完毕之后给出反
        //向本机的10001端口发送数据
        Socket socket = new Socket("127.0.0.1", 10001);

        File file = new File("day30-code\\file\\a.txt");
        //
        FileInputStream fis = new FileInputStream(file);
        BufferedInputStream bis = new BufferedInputStream(fis);
        //这里记得关流,不然数据2传输不过去
        OutputStream os = socket.getOutputStream();
        BufferedOutputStream bos = new BufferedOutputStream(os);
        int b;
        while ((b = bis.read()) != -1) {
            bos.write((char) b);
            System.out.println((char) b);
        }
        bos.flush();
        socket.shutdownOutput();//结束标志位

        //写入数据流关闭
        bis.close();

        //接受服务器回写的数据
        BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
        String s;
        while ((s = br.readLine()) != null) {
            System.out.println(s);
        }
        br.close();

        socket.close();


    }
}
